{% extends "shuup/admin/base.jinja" %}
{% from "shuup/admin/macros/general.jinja" import content_with_sidebar, content_block %}

{% block content %}
    <div class="container-fluid">
    {% call content_block(_("Data Import"), "fa-info-circle") %}
        <form method="post" enctype="multipart/form-data" action="" id="import_form">
            {% csrf_token %}
            <input type="hidden" name="next" value="{{ url("shuup_admin:importer.import_process") }}">
            {{ bs3.field(form.language) }}
            {{ bs3.field(form.shop) }}
            {{ bs3.field(form.importer) }}
            <div class="col-12">
                {{ bs3.field(form.file) }}
            </div>
            <div class="col-md-6 col-md-offset-3">
                {% if importer and importer.has_example_file() %}
                <h2>{% trans %}Example files{% endtrans %}</h2>
                <p>
                    {% trans %}If there is a 'Ignore' column in the example file you are using,
                    make sure to leave the ignore column empty for all your rows,
                    otherwise the rows won't be imported.{% endtrans %}
                </p>
                <p>{% trans %}This importer provides example files. Click below to download them:{% endtrans %}</p>
                <ul>
                    {% for example_file in importer.example_files %}
                    <li>
                        <a href="{{ url("shuup_admin:importer.download_example") }}?importer={{ importer.identifier }}&file_name={{ example_file.file_name }}" target="_blank">
                            {{ example_file.file_name }}
                        </a>
                    </li>
                    {% endfor %}
                </ul>
                {% endif %}
                {% if importer and importer.help_template %}
                    {% include importer.help_template with context %}
                {% endif %}
            </div>
            <input type="submit" value="{% trans %}Continue{% endtrans %}" id="basic-form-save" class="btn btn-primary btn-block">
        </form>
    {% endcall %}
    </div>
{% endblock %}

{% block extra_js %}
    {{ super() }}
    <script>
        $(function () {
            $("#{{ form.importer.id_for_label }}").on("change", function() {
                location.href = "{{ url('shuup_admin:importer.import') }}?importer=" + $(this).val();
            });
        });
    </script>
{% endblock %}
